"""
最高优先级：|  分小节  优先级1

识别{} 组合，优先级2  需要成对出现，由内向外 分层

识别_{ 组合



"""

import re

# from string import maketrans   # 引用 maketrans 函数。
 
# intab = "aeiou"
# outtab = "12345"
# trantab = maketrans(intab, outtab)
 
# str = "this is string example....wow!!!"
# print(str.translate(trantab)




# a = '1 2 4 5| (12) 12_{_} (33) 2*{.}|'
# b = '(12) 12_{_} (33) 2^{.}'
# # b = 'Hello World Wide Web'
# print(b.count('{'))
# print(b.index('{'))

# print(b[3:5])

# print(b.split('{'))

# pattern = re.compile(r'.*[{].*[}].*', re.S)  #这个可以，但是就是原字符串

# pattern = re.compile(r'[{].*[}]', re.S)  # 不行
# pattern = re.compile(r'[{](.*)[}]', re.S)  # 不行
# pattern = re.compile('\{.*\}', re.S) # 不行
# pattern = re.compile(r'([a-z]+) ([a-z]+)', re.I)
# result = pattern.match(b)

# result = re.findall('\{.*\}',b) #不行


# print(result)
# print(result.group())




def get_all_indexs(string,pattern):
    indexs = []
    for i in range(len(string)):
        if b[i] == pattern:
            indexs.append(i)

    return indexs


# lh_indexs = get_all_indexs(b,'{')
# rh_indexs = get_all_indexs(b,'}')








def clip_section(s):
    s_list = s.split('|')
    return s_list


def clip_braces(s):
    l_count = s.count('{')
    r_count = s.count('}')
    if l_count != r_count:
        return s 
    else:
        pair = 1



# a = '1 2 3  4 5 6 7'
# eles = [i for i in a.split(' ') if i not in [' ','']]
# print(eles)








# 幻昼

section = '| 0 0 3^{..} 5^{..} |= 2^{..} 2^{..} 1^{..} {7^{.}5^{..}}_{_} | 2^{..} 2^{..} 1^{..} {7^{.}3^{..}}_{_} | 1^{..} 1^{..} 7^{.} 6^{.} |'
section = '| 0 0 3^.. 5^.. |= 2^.. 2^.. 1^.. {7^.5^..}_ | 2^.. 2^.. 1^.. {7^.3^..}_ | 1^.. 1^.. 7^. 6^. |'
section = '| 0 0 3^.. 5^.. |= 2^.. 2^.. 1^.. {7^.5^..}_ | 2^.. 2^.. 1^.. {7^.3^..}_ | 1^.. 1^.. 7^. 6^. |'
section = '|{6^.5^.}..3_.}|'

section = '| 3__6_(7__ 7__)1^.(2^.__ | 2^._)1^._ 1^.__6_(7__ | 7) 0_3__3__   '

from analysis import RE

r = RE()
sections = r.getSections(section)
print(sections)

new_sections = []
for s in sections:
    element  = r.convertElement(s)
    new_sections.append(element)
print(new_sections)
